package edu.gyc.data.struct.sparsearray;

import java.io.*;

public class MyData implements Serializable {
    private int[][] sparseArr;

    public int[][] getSparseArr() {
        return sparseArr;
    }

    public void setSparseArr(int[][] sparseArr) {
        this.sparseArr = sparseArr;
    }

    public boolean saveData() {
        try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("d:/chess.data"));
            oos.writeObject(this);
            oos.close();
            System.out.println("chess data store ok;");
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        } finally {
        }
    }

    public boolean readData() {
        try {
            ObjectInputStream oos = new ObjectInputStream(new FileInputStream("d:/chess.data"));
           MyData data= (MyData) oos.readObject();
            oos.close();
            System.out.println("read chess data  ok;");
            System.out.println("还原的稀疏数组：");
            int[][] sparseArr=data.getSparseArr();
            for (int i = 0; i < sparseArr.length; i++) {
                System.out.printf("%d\t%d\t%d\t\n", sparseArr[i][0], sparseArr[i][1], sparseArr[i][2]);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
        }
    }
}